﻿using System;
using System.Diagnostics;
using System.ComponentModel;
using System.IO;
using System.Net;

namespace Spotted
{
    public class Classifier
    {

        private static Action Callback;
        public static String feed;


        public static void classifyTest(String imagePath, Action callback)
        {
            Callback = callback;
           try{ 
                System.Uri uri = new Uri("http://spottedapp.cloudapp.net:8080/examples/queryMatlab");
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                request.Headers["x-image-path"] = imagePath;
                IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(RespCallbackMatlab), request);
              
           } catch (Exception e)
            {

                

            }
        }


         private static void RespCallbackMatlab(IAsyncResult result)
        {
            try
            {
                HttpWebRequest request = result.AsyncState as HttpWebRequest;

                if (request != null)
                {
                    using (WebResponse response = request.EndGetResponse(result))
                    {
                        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                        {
                             feed = reader.ReadToEnd();
                           
                        }

                    }
                    Callback();
                }
            }

            catch (WebException e)
            {
                
            }
        }
   
        
        

       
    }

}
